package com.csd.fragment;

import com.csd.activity.PaymentActivity;
import com.csd.activity.PersonalDetailActivity;
import com.csd.activity.R;
import com.csd.bean.Car;
import com.csd.bean.EnterpriseOrder;
import com.csd.bean.PersonalOrder;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class SettleFragment extends Fragment implements OnClickListener {

	private View view;
	private TextView tv_orderId, tv_carBrand, tv_plate, tv_taketime,
			tv_returntime, tv_state,  tv_payment, tv_txt;
	private ImageView img_car;
	private LinearLayout ll_detail,ll_bt;
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		view = inflater.inflate(R.layout.personalorder, null);
		init();
		return view;
	}

	private void init() {
		// TODO Auto-generated method stub
		tv_orderId = (TextView) view.findViewById(R.id.orderid);
		tv_state = (TextView) view.findViewById(R.id.state);
		tv_carBrand = (TextView) view.findViewById(R.id.carbrand);
		tv_plate = (TextView) view.findViewById(R.id.plate);
		tv_taketime = (TextView) view.findViewById(R.id.taketime);
		tv_returntime = (TextView) view.findViewById(R.id.returntime);
		tv_txt = (TextView) view.findViewById(R.id.pay_txt);
		tv_payment = (TextView) view.findViewById(R.id.payment);
		img_car = (ImageView) view.findViewById(R.id.carimg);
		ll_detail = (LinearLayout) view.findViewById(R.id.detail);
		ll_detail.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(),
						PersonalDetailActivity.class);
				startActivity(intent);
			}
		});
		PersonalOrder order = new PersonalOrder();
		order.setOrderId("CWDD-0035");
		Car car = new Car();
		car.setImg(R.drawable.u120);
		car.setCarBrand("丰田威驰");
		car.setPlate("沪A-3245");
		order.setCar(car);
		order.setTakeTime("2014/11/19 18:00");
		order.setReturnTime("2014/11/19 20:00");
		order.setPayment(150);
		order.setState("待结清");
		ll_bt = (LinearLayout) view.findViewById(R.id.ll_bt);
		if (order.getState().equals("待结清")) {
			Button bt_pay = new Button(getActivity());
			bt_pay.setText("付款");
			bt_pay.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(getActivity(), PaymentActivity.class);
					startActivity(intent);
				}
			});
			
			ll_bt.addView(bt_pay);
		}
		tv_orderId.setText(order.getOrderId());
		tv_state.setText(order.getState());
		tv_carBrand.setText(order.getCar().getCarBrand());
		tv_plate.setText(order.getCar().getPlate());
		tv_orderId.setText(order.getOrderId());
		tv_state.setText(order.getState());
		tv_carBrand.setText(order.getCar().getCarBrand());
		tv_plate.setText(order.getCar().getPlate());
		tv_taketime.setText(order.getTakeTime());
		tv_returntime.setText(order.getReturnTime());
		if(order.getState().equals("待付款")){
			tv_txt.setText("应付款");
		}else if(order.getState().equals("已付款")){
			tv_txt.setText("实付款：");
		}
		tv_payment.setText("￥"+order.getPayment());
		img_car.setImageResource(order.getCar().getImg());tv_taketime.setText(order.getTakeTime());
		tv_returntime.setText(order.getReturnTime());
		if(order.getState().equals("待结清")){
			tv_txt.setText("应付尾款：");
		}
		tv_payment.setText("￥"+order.getPayment());
		img_car.setImageResource(order.getCar().getImg());

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == ll_detail) {
			Intent intent = new Intent(getActivity(), PersonalDetailActivity.class);
			startActivity(intent);
		}
	}
}
